package ce.com.cenewbluesdk.uitl;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public abstract class BaseBroadcastReceiver extends BroadcastReceiver {

    public BaseBroadcastReceiver() {
    }

    @Override
    public abstract void onReceive(Context context, Intent intent);

    /**
     * 废弃, 推荐重写{@link #onCreateFilter(IntentFilter)}方法, 写起来更方便~~
     */
    @Deprecated
    protected IntentFilter createIntentFilter() {
        return new IntentFilter();
    }

    public void register(Context context) {
        IntentFilter filter = createIntentFilter();
        onCreateFilter(filter);
        context.registerReceiver(this, filter);
    }

    protected void onCreateFilter(IntentFilter filter) {
    }

    public void unregister(Context context) {
        context.unregisterReceiver(this);
    }
}
